<?php

/**
 *  @FileComment            [用户角色模型]
 *  @ProjectName             项目名称：JDshop
 *  @FileName                   文件名称：RoleModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-26 0:04:41
 *  *
 */
class RoleModel extends Model {

        public $table = 'role';
        public $validate = array(
            array('rname', 'nonull', '角色名不能为空', 2, 3),
            array('rname', '_isset', '角色名已存在', 2, 3)
        );

        public function _isset($name, $value, $msg, $arg) {
                $data = $this->where(array('rname' => $value))->find();
                if (!empty($data)) {
                        return $msg;
                } else {
                        return true;
                }
        }

        public function get_data() {
                return $this->all();
        }

        public function add_data() {
                return $this->add();
        }

        public function del_data($rid) {
                //删除角色用户中间表的相关数据
                K('AdminRole')->where(array('rid' => $rid))->del();
                //删除角色表中的角色
                return $this->where(array('rid' => $rid))->del();
        }

}
